//package com.example.shiwu;
//
//import android.Manifest;
//import android.annotation.SuppressLint;
//import android.location.Address;
//import android.location.LocationListener;
//import android.location.LocationManager;
//import android.os.Build;
//import android.os.Bundle;
//import android.view.View;
//import android.widget.TextView;
//
//import androidx.annotation.NonNull;
//import androidx.annotation.RequiresApi;
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.example.shiwu.util.LocationNewUtils;
//import com.github.dfqin.grantor.PermissionListener;
//import com.github.dfqin.grantor.PermissionsUtil;
//
///**
// * Created by Jay on 2015/11/20 0020.
// */
//public class GpsListBcakActivity extends AppCompatActivity {
//    // 定义TextView
//    private TextView nowAddress;
//    private TextView lat;
//    private TextView lon;
//    // 定义双精度类型的经纬度
//    private Double longitude,latitude;
//    // 定义位置管理器
//    private LocationManager locationManager;
//    private static final String TAG = "GpsListActivity";
//
//    private String locationProvider;
//    private LocationManager lm;
//    private TextView tv_show,tv_show2,tv_show3;
//    private TextView tv_show_foucs;
//    private LocationListener locationListener;
//    /**
//     * Android 10及以上申请权限
//     */
////申请的权限
//    private static final String[] mPermissions = {Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION};
//    public static final int RESULT_CODE = 1001;
//    @SuppressLint("MissingPermission")
//    @RequiresApi(api = Build.VERSION_CODES.M)
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_gps);
//        // 得到对应视图ID
//        tv_show = (TextView) findViewById(R.id.tv_show);
//        tv_show2 = (TextView) findViewById(R.id.tv_show2);
//        tv_show3 = (TextView) findViewById(R.id.tv_show3);
//
//        requestPermissions();
//        //initLocation();
//
//        //methodRequiresTwoPermission();
//        tv_show.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                tv_show_foucs = tv_show;
////                if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.R){
////                    requestPermission.launch(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
////                }
//
//                // 注意，不会有系统弹框，需要我们自己写代码，让用户跳转到设置页面去选择
//
//
//                requestPermissions();
//            }
//        });
//        tv_show2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                tv_show_foucs = tv_show2;
//                requestPermissions();
//            }
//        });
//        tv_show3.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                tv_show_foucs = tv_show3;
//                requestPermissions();
//            }
//        });
//
//    }
//
//    //动态权限框架
////    @AfterPermissionGranted(RESULT_CODE)
////    private void methodRequiresTwoPermission() {
////        String[] perms = {Manifest.permission.INTERNET, Manifest.permission.ACCESS_FINE_LOCATION};
////        if (EasyPermissions.hasPermissions(GpsListActivity.this, perms)) {
//////            final Intent intentStart = new Intent(GpsListActivity.this, LocationServer.class);
//////            startService(intentStart);
////            Log.e("sss","绑定服务");
////            bindService(new Intent(this, LocationServer.class), this, BIND_AUTO_CREATE);
////        } else {
//////            EasyPermissions.requestPermissions(GpsListActivity.this, "请求获取您的位置信息和本地读写权限",
//////                    RESULT_CODE, perms);
////            AlertDialog.Builder builder = new AlertDialog.Builder(this);
////            builder.setTitle("需要位置信息")
////                    .setMessage("该应用需要访问位置信息以提供更好的服务。")
////                    .setPositiveButton("允许", (dialog, which) -> {
////                        ActivityCompat.requestPermissions(this,
////                                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
////                                2);
////                    })
////                    .setNegativeButton("拒绝", (dialog, which) -> dialog.dismiss())
////                    .show();
////        }
////    }
////
////    @Override
////    protected void onResume() {
////        super.onResume();
////        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
////                != PackageManager.PERMISSION_GRANTED) {
////            ActivityCompat.requestPermissions(this,
////                    new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
////                    1);
////        }
////
////    }
////
////
////
////    @Override
////    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
////        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
////
////        // Forward results to EasyPermissions
////        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
////    }
////
////
////    @Override
////    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
////        Log.e("ss","绑定回调");
////        LocationServer.Binder binder = (LocationServer.Binder) iBinder;
////        LocationServer myService = binder.getService();
////        myService.setCallback(new LocationServer.Callback() {
////            @Override
////            public void onDataChange(Location location) {
////                Message msg = new Message();
////                msg.obj = location;
////                handler.sendMessage(msg);
////                String strcontent=location.getLatitude()+","+location.getLongitude()+","+location.getAccuracy();
////                // 每次写入时，都换行写
////                String strContent = strcontent + "\r\n";
////                Log.e("定位结果",strContent);
////                Toast.makeText(GpsListActivity.this,strContent,Toast.LENGTH_LONG).show();
////
////            }
////        });
////    }
////
////
////    @Override
////    public void onServiceDisconnected(ComponentName componentName) {
////
////    }
////
////
////    private final Handler handler = new Handler() {
////        @Override
////        public void handleMessage(Message msg) {
////            super.handleMessage(msg);
////            Toast.makeText(GpsListActivity.this, msg.obj.toString(), Toast.LENGTH_LONG);
////            tv_show_foucs.setText(msg.obj.toString());
////
////
////        }
////    };
//
//
//
//
//
//
//    /**
//     * 请求权限
//     */
//    private void requestPermissions() {
////        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
////                != PackageManager.PERMISSION_GRANTED) {
////            // 权限未被授予，请求权限
////            ActivityCompat.requestPermissions(this,
////                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
////                    1);
////        } else {
////            // 权限已被授予，可以执行获取位置的操作
////            initLocation();
////        }
//        if (PermissionsUtil.hasPermission(GpsListBcakActivity.this,mPermissions)) {
//            //有访问权限
//            initLocation();
//        } else {
//            PermissionsUtil.requestPermission(this, new PermissionListener() {
//                @Override
//                public void permissionGranted(@NonNull String[] permissions) {
//                    //用户授予了访问权限
//                    initLocation();
//                }
//                @Override
//                public void permissionDenied(@NonNull String[] permissions) {
//                    //用户拒绝了访问的申请
//                   // initLocation();
//                }
//            }, mPermissions);
//        }
//    }
//
//    /**
//     * 加载位置
//     */
//    private void initLocation() {
//        LocationNewUtils.getInstance(this).setAddressCallback(new LocationNewUtils.AddressCallback() {
//            @Override
//            public void onGetAddress(Address address) {
//                String countryName = address.getCountryName();//国家
//                String adminArea = address.getAdminArea();//省
//                String locality = address.getLocality();//市
//                String subLocality = address.getSubLocality();//区
//                String featureName = address.getFeatureName();//街道
//               // LogUtils.eTag("定位地址",countryName,adminArea,locality,subLocality,featureName);
//                tv_show.setText( "定位地址" );
//            }
//
//            @Override
//            public void onGetLocation(double lat, double lng) {
//                tv_show.setText( "定位"+lat+" - "+lng );
//            }
//        });
//    }
//
//
//
//}